package com.lanou.impl;

import com.github.pagehelper.PageHelper;
import com.lanou.mapper.securityDeposit;
import com.lanou.pojo.PaymentDepositEntity;
import com.lanou.pojo.PaymentMethod;
import com.lanou.service.depositService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class depositServiceimpl implements depositService {
    @Resource
    private securityDeposit securityDeposit;
    @Override
    public List<PaymentDepositEntity> paymentDepositList(String pageNum ,String pageSize,String resourceName, String feeUser, String state, String feeItemName, String payType) {

//        处理分页查询
        if(pageNum == null || "".equals(pageNum)){
            pageNum="1";
        }
        if(pageSize == null || "".equals(pageSize)){
            pageSize="5";
        }
        PageHelper.startPage(Integer.valueOf(pageNum),Integer.valueOf(pageSize));
        List<PaymentDepositEntity> paymentDepositList = securityDeposit.paymentDepositList(resourceName, feeUser, state, feeItemName, payType);
        List<PaymentMethod> paymentMethods = securityDeposit.selectPayMethod();
        for (PaymentDepositEntity code : paymentDepositList) {
            for(PaymentMethod name:paymentMethods)
                    if (code.getPayType().equals(name.getCode())) {
                         code.setPayType(name.getName());
                    }
                }


        return paymentDepositList;
    }


    @Override
    public void addPaymentDeposit(String resourceName, String feeUser, String feeItemName, String payType, String amt ,Date operateTime) {
       String  id=controllerServiceImpl.generateRandomNumber(19);
       String resourceId=controllerServiceImpl.generateRandomNumber(19);
      String feeItemId=controllerServiceImpl.generateRandomNumber(19);

        securityDeposit.addPaymentDeposit(id,resourceId, resourceName, feeUser, feeItemName, payType, amt ,operateTime,feeItemId);
    }

    @Override
    public void updateByid(Date refundTime,String remark, String refundType, String id) {
        securityDeposit.updateByid(refundTime,remark,refundType,id);
        System.out.println("更新成功");
    }

    @Override
    public List<PaymentMethod> selectPayMethod() {
        List<PaymentMethod> PayMethods = securityDeposit.selectPayMethod();
        return PayMethods;
    }

    @Override
    public List<String> selectpaymentContract() {
        List<String> list = securityDeposit.paymentContract();
        return list;
    }
}
